package work.stackandqueque;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.util.LinkedList;
import java.util.Queue;

public class Problem255 {
    class MyStack {
        private Queue<Integer> A;
        private Queue<Integer> B;
        //ture A FASLE b
        boolean tag = true;

        public MyStack() {
            A = new LinkedList<>();
            B = new LinkedList<>();
        }

        public void push(int x) {
            if (A.isEmpty()) {
                A.add(x);
                while (!B.isEmpty()) {
                    Integer poll = B.poll();
                    A.add(poll);
                }
            } else {
                B.add(x);
                while (!A.isEmpty()) {
                    Integer poll = A.poll();
                    B.add(poll);
                }
            }
        }

        public int pop() {
            if (A.isEmpty()) return B.poll();
            else return A.poll();
        }

        public int top() {
            if (A.isEmpty()) return B.peek();
            else return A.peek();
        }

        public boolean empty() {
            if (A.isEmpty() && B.isEmpty()) return true;
            else return false;
        }
    }
}
